package com.dynamic.mybatis.core.parser.xml.expand;

import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.QName;
import org.xml.sax.Locator;

/**
 * @Description
 * @Author xs
 * @Date 2023/4/21 10:33
 */
public class MyDocumentFactory extends DocumentFactory {
    private Locator locator;

    public MyDocumentFactory(Locator locator) {
        super();
        this.locator = locator;
    }

    @Override
    public Element createElement(QName qname) {
        MyDefaultElement element = new MyDefaultElement(qname);
        element.setLocation(this.locator.getLineNumber(), this.locator.getColumnNumber());
        return element;
    }

    @Override
    public Element createElement(String name) {
        MyDefaultElement element = new MyDefaultElement(name);
        element.setLocation(this.locator.getLineNumber(), this.locator.getColumnNumber());
        return element;
    }

    public void setLocator(Locator locator) {
        this.locator = locator;
    }
}